# Maintainer: Antonio Rojas <arojas@archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - add LDFLAGS and CXXOPT to lower RAM usage
#  - make -j2 due to RAM constraints

highmem=1

pkgname=polymake
pkgver=4.12
pkgrel=2
_perlver=`perl -e '$v = $^V->{version}; print $v->[0].".".($v->[1]).".".($v->[2]);'`
pkgdesc='Open source software for research in polyhedral geometry'
arch=(x86_64)
url='https://polymake.org/'
license=(GPL)
depends=(bliss
         cddlib
         e-antic
         flint
         gcc-libs
         glibc
         gmp
         lrs
         mpfr
         normaliz
         perl=$_perlver
         perl-json
         perl-term-readkey
         perl-term-readline-gnu
         perl-xml-libxml
         perl-xml-libxslt
         perl-xml-writer
         ppl
         scip
         singular
         sympol
         zlib)
makedepends=(ant
             boost
             jdk-openjdk
             libnsl
             nauty
             ninja
             permlib
             soplex)
optdepends=('java-runtime: java module')
source=(https://polymake.org/lib/exe/fetch.php/download/polymake-${pkgver/.r/r}-minimal.tar.bz2
        lrs-073.patch)
sha256sums=('bd5a667ffca4bf7eb8d51134030ce3df3b16dd9d0e800fafdb1ce835867640d9'
            '4795e9fc2dd23546ca7f6a112695f09f6b745517cff387a0f9f54aecf3272ef7')

prepare() {
  sed -e 's|-lgmp|-lgmp -lmpfr|g' -i polymake-$pkgver/bundled/soplex/support/configure.pl # Fix soplex linking
  patch -d polymake-$pkgver -p1 < lrs-073.patch # Fix build with lrs 073
}

build() {
  cd polymake-$pkgver
  ./configure \
    --prefix=/usr \
    --without-native \
    --with-cdd=/usr \
    --with-lrs=/usr \
    --with-permlib=/usr \
    --with-soplex=/usr \
    --with-sympol=/usr CXXOPT="-O1"
  LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
  make -j2
}

package() {
  cd polymake-$pkgver
  make DESTDIR="$pkgdir" install

# Executables are installed in mode 555, which breaks strip
  find "$pkgdir" -exec chmod u+w {} +
}
